<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="list" style="display:flex ; text-align:center;"></div>
    <button id="back">▲</button>
    <button id="next">▼</button><span class="ber">1/4</span>
</body>

</html>
<script>
    var page = 1
    function data(obj) {
        var str = '';
        for (var key in obj) {
            str += `${key}=${obj[key]}&`
        }
        return str.slice(0, str.length - 1);

    }
    function ajax(method, url, params, cd) {
        var xhr = new XMLHttpRequest();

        xhr.open(method, url + "?" + data(params))

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                cd(JSON.parse(xhr.responseText))
            }
        }
        xhr.send();



    }
    ajax('get', `https://yantianfeng.com/api/emotion`, { page: 1, count: 10 }, function (num) {
        var str = num.emotions.map((item, index) => {
            return `<div> <img src="${item.url}"/> <div>${item.title}</div></div>`
        }).join('')
        document.querySelector('.list').innerHTML = str;

    })



    var btn1 = document.getElementById("back")
    var btn2 = document.getElementById("next")

    btn1.disabled = true

    btn1.onclick = function () {
        if (page > 1) {
            ajax('get', `https://yantianfeng.com/api/emotion`, { page: --page, count: 10 }, function (num) {
                var str = num.emotions.map((item, index) => {
                    return `<div> <img src="${item.url}"/> <div>${item.title}</div></div>`
                }).join('')
                document.querySelector('.list').innerHTML = str;
            })
            btn2.disabled = false

        } else if (page = 1) {
            btn1.disabled = true
        }
        document.querySelector('.ber').innerHTML = `${page}/4`
    }




   

    btn2.onclick = function () {
        if (page < 4) {
            btn1.disabled = false
            ajax('get', `https://yantianfeng.com/api/emotion`, { page: ++page, count: 10 }, function (num) {
                var str = num.emotions.map((item, index) => {
                    return `<div> <img src="${item.url}"/> <div>${item.title}</div></div>`
                }).join('')
                document.querySelector('.list').innerHTML = str
            })
        } else if (page = 4) {
            btn2.disabled = true
        }

       
        document.querySelector('.ber').innerHTML = `${page}/4`

    }
   



</script>